package com.xidian.zhiancloud.controller.helpCenter;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xidian.zhiancloud.controller.base.BaseController;
import com.xidian.zhiancloud.dto.ResultDTO;
import com.xidian.zhiancloud.enums.GeneralResponseEnums;
import com.xidian.zhiancloud.model.DataDownload;
import com.xidian.zhiancloud.qo.helpCenter.DataDownloadQO;
import com.xidian.zhiancloud.service.helpCenter.DataDownloadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 帮助中心 资料下载接口
 */
@RestController
@RequestMapping("/DataDownload")
public class DataDownloadController extends BaseController {

    @Autowired
    private DataDownloadService dataDownloadService;

    /**
     * 根据id获取资料下载
     * @param id 资料下载对象id
     * @return 资料下载对象
     */
    @GetMapping("/getById")
    public ResultDTO<DataDownload> getById(@RequestParam("id") Long id){
        return ResultDTO.successOf(dataDownloadService.getById(id), GeneralResponseEnums.SUCCESS);
    }

    /**
     * 条件查询
     * @param dataDownloadQO 查询条件
     * @return 返回查询列表
     */
    @GetMapping("/getListByQO")
    public ResultDTO<IPage<DataDownload>> getListByQueryObject(DataDownloadQO dataDownloadQO) {
        if(dataDownloadQO.getCurrent() == null || dataDownloadQO.getSize() ==null){
            return ResultDTO.errorOf(GeneralResponseEnums.REQUEST_ERROR);
        }
        dataDownloadQO.setCompanyId(getSessionUserCompanyId());
        return ResultDTO.successOf(dataDownloadService.getListByQO(dataDownloadQO), GeneralResponseEnums.SUCCESS);
    }
}
